package light.head.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Formula;

/**
 * 组织机构
 * @author Jian
 */
@Entity
@Table
public class Organ implements Serializable {

	private static final long serialVersionUID = 7903617044133944474L;
	
	private Integer code;
	private String name;
	private String abbname;							// 简称
	private String site;							// 网址
	private String logo;							// logo路径
	private String pinyin;							// 机构名称全拼
	private String py;								// 机构名称拼音首字母
	private Boolean isUsing;						// 是否在使用
	private String manager;							// 负责人姓名
	private String bank;							// 帐号开户行
	private String account;							// 银行帐号
	private Integer pc;								// 父机构编号
	private Date ct = new Date();					// 创建时间
	private Boolean deleted = false;				// 是否删除
	private Integer otc;							// 机构类型编号
	private Integer cu;								// 创建用户
	private Integer mc;								// 管理员编号，默认为创建用户编号

	
	private String pn;								// 父机构名称
	private String mn;								// 管理员姓名
	private String otn;								// 机构类型名称
	private String cun;								// 创建用户真实姓名
	
	private Integer sonCount;						// 下级机构总数
	private List<Organ> sonList;					// 下级机构列表
	
	private OrganDetails details;					// 机构详情
	private OrganSynopsis synopsis;					// 机构简介
	private List<OrganSynopsisAnnex> list;			// 机构展示图片 
	


	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column
	public Integer getCode() {
		return code;
	}
	
	@Column(length = 100)
	public String getName() {
		return name;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false, nullable = false)
	public Date getCt() {
		return ct;
	}

	@Column
	public Integer getCu() {
		return cu;
	}
	
	@Column
	public Integer getOtc() {
		return otc;
	}

	@Column
	public Boolean getDeleted() {
		return deleted;
	}

	@Column
	public Integer getPc() {
		return pc;
	}
	
	@Column
	public Integer getMc() {
		return mc;
	}

	@Column(length = 200)
	public String getLogo() {
		return logo;
	}

	@Column(length = 100)
	public String getSite() {
		return site;
	}

	@Column(length = 20)
	public String getManager() {
		return manager;
	}
	@Column
	public String getBank() {
		return bank;
	}
	@Column(length = 20)
	public String getAccount() {
		return account;
	}
	@Column(length = 50)
	public String getPinyin() {
		return pinyin;
	}
	@Column(length = 20)
	public String getPy() {
		return py;
	}
	@Column
	public Boolean getIsUsing() {
		return isUsing;
	}
	@Column
	public String getAbbname() {
		return abbname;
	}

	
	@Formula("(SELECT o.name FROM Organ o WHERE o.code = pc)")
	public String getPn() {
		return pn;
	}
	
	@Formula("(SELECT ot.name FROM OrganType ot WHERE ot.code = otc)")
	public String getOtn() {
		return otn;
	}

	@Formula("(SELECT u.realName FROM UserInfo u WHERE u.code = cu)")
	public String getCun() {
		return cun;
	}
	
	@Formula("(SELECT u.realName FROM UserInfo u WHERE u.code = mc)")
	public String getMn() {
		return mn;
	}

	@Formula("(SELECT COUNT(*) FROM Organ o WHERE (o.deleted = 0 OR o.deleted IS NULL) AND o.pc = code)")
	public Integer getSonCount() {
		return sonCount;
	}
	

	@Transient
	public List<Organ> getSonList() {
		return sonList;
	}

	@Transient
	public OrganDetails getDetails() {
		return details;
	}
	
	@Transient
	public OrganSynopsis getSynopsis() {
		return synopsis;
	}
	
	@Transient
	public List<OrganSynopsisAnnex> getList() {
		return list;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	




	public void setAbbname(String abbname) {
		this.abbname = abbname;
	}

	public void setSynopsis(OrganSynopsis synopsis) {
		this.synopsis = synopsis;
	}

	public void setDetails(OrganDetails details) {
		this.details = details;
	}

	public void setPinyin(String pinyin) {
		this.pinyin = pinyin;
	}

	public void setPy(String py) {
		this.py = py;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}

	public void setAccount(String account) {
		this.account = account;
	}
	public void setIsUsing(Boolean isUsing) {
		this.isUsing = isUsing;
	}

	public void setCode(Integer code) {
		this.code = code;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}
	public void setSite(String site) {
		this.site = site;
	}
	public void setLogo(String logo) {
		this.logo = logo;
	}
	public void setPc(Integer pc) {
		this.pc = pc;
	}
	public void setCt(Date ct) {
		this.ct = ct;
	}
	public void setOtc(Integer otc) {
		this.otc = otc;
	}
	public void setCu(Integer cu) {
		this.cu = cu;
	}
	public void setOtn(String otn) {
		this.otn = otn;
	}
	public void setCun(String cun) {
		this.cun = cun;
	}
	public void setMc(Integer mc) {
		this.mc = mc;
	}
	public void setPn(String pn) {
		this.pn = pn;
	}
	public void setMn(String mn) {
		this.mn = mn;
	}
	public void setSonCount(Integer sonCount) {
		this.sonCount = sonCount;
	}
	public void setSonList(List<Organ> sonList) {
		this.sonList = sonList;
	}
	public void setManager(String manager) {
		this.manager = manager;
	}
	public void setList(List<OrganSynopsisAnnex> list) {
		this.list = list;
	}
}
